﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication2
{
    public class Form1Presenter
    {
        IRepository<Contact> _contactsRepository;
        IRepository<TaskItem> _taskItemsRepository;
        IRepository<Product> _productsRepository;

        IEnumerable<Contact> _contacts;
        IEnumerable<TaskItem> _taskItems;
        IEnumerable<Product> _products;
        

        public Form1Presenter(IRepository<Contact> contactsRepository, 
            IRepository<TaskItem> taskItemsRepository, IRepository<Product> productsRepository)
        {           
            _contactsRepository = contactsRepository;
            _taskItemsRepository = taskItemsRepository;
            _productsRepository = productsRepository;           

        }

        public IEnumerable<Contact> Contacts 
        {
            get
            {
                if (_contacts==null)
                {
                    _contacts = _contactsRepository.Read("Select * from Contacts");
                }
                return _contacts;
            }
        }

        public IEnumerable<TaskItem> TaskItems
        {
            get
            {
                if (_taskItems == null)
                {
                    _taskItems = _taskItemsRepository.Read("Select * from Tasks");
                }
                return _taskItems;
            }
        }
        public IEnumerable<Product> Products
        {
            get
            {
                if (_products == null)
                {
                    _products = _productsRepository.Read("Select * from Products");
                }
                return _products;
            }
        }
    }
}
